document.addEventListener('DOMContentLoaded', function() {
    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'http://localhost:3000/students', true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var students = JSON.parse(xhr.responseText);
            var tableBody = document.getElementById('students').getElementsByTagName('tbody')[0];
            students.forEach(function(student) {
                var row = tableBody.insertRow();
                row.insertCell(0).textContent = student.id;
                row.insertCell(1).textContent = student.name;
                row.insertCell(2).textContent = student.age;
                row.insertCell(3).textContent = student.major;
                row.insertCell(4).textContent = student.grade;
            });
        }
    };
    xhr.send();
});